# In our example, we draw nine different rectangles using 9 different brush styles.

import sys, random
from PySide import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

    # Drawing is done within a paintEvent
    def paintEvent(self, event):
        # QtGui.QPainter class is responsible for all the low level painting. All the painting event go between begin()
        # and the end() methods. The actual painting in this program is delegated to the 'drawText' method
        painter = QtGui.QPainter()
        painter.begin(self)
        self.drawBrushes(event, painter)
        painter.end()

        self.setGeometry(200, 200, 350, 300)
        self.setWindowTitle("Drawing-Brushes")

    def drawBrushes(self, event, painter):
        # We define a brush object. Set it to the painter object. And draw the rectangle calling the drawRect() method.
        brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
        painter.setBrush(brush)
        painter.drawRect(10, 15, 90, 60)

        brush.setStyle(QtCore.Qt.Dense1Pattern)
        painter.setBrush(brush)
        painter.drawRect(130, 15, 90, 60)

        brush.setStyle(QtCore.Qt.Dense2Pattern)
        painter.setBrush(brush)
        painter.drawRect(250, 15, 90, 60)

        brush.setStyle(QtCore.Qt.Dense3Pattern)
        painter.setBrush(brush)
        painter.drawRect(10, 105, 90, 60)

        brush.setStyle(QtCore.Qt.DiagCrossPattern)
        painter.setBrush(brush)
        painter.drawRect(10, 105, 90, 60)

        brush.setStyle(QtCore.Qt.Dense5Pattern)
        painter.setBrush(brush)
        painter.drawRect(130, 105, 90, 60)

        brush.setStyle(QtCore.Qt.Dense6Pattern)
        painter.setBrush(brush)
        painter.drawRect(250, 105, 90, 60)

        brush.setStyle(QtCore.Qt.HorPattern)
        painter.setBrush(brush)
        painter.drawRect(10, 195, 90, 60)

        brush.setStyle(QtCore.Qt.VerPattern)
        painter.setBrush(brush)
        painter.drawRect(130, 195, 90, 60)

        brush.setStyle(QtCore.Qt.BDiagPattern)
        painter.setBrush(brush)
        painter.drawRect(250, 195, 90, 60)


if __name__ == "__main__":
    appObject = QtGui.QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(appObject.exec_())

